/// 🔄 分享响应模型
/// 
/// 服务器返回的分享链接信息
class ShareResponse {
  final String status;
  final String? message;
  final ShareData? data;

  ShareResponse({
    required this.status,
    this.message,
    this.data,
  });

  /// 是否成功
  bool get isSuccess => status == 'success';

  /// 从JSON创建
  factory ShareResponse.fromJson(Map<String, dynamic> json) {
    return ShareResponse(
      status: json['status'] ?? 'error',
      message: json['message'],
      data: json['data'] != null ? ShareData.fromJson(json['data']) : null,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'status': status,
      if (message != null) 'message': message,
      if (data != null) 'data': data!.toJson(),
    };
  }
}

/// 🔗 分享数据
class ShareData {
  final int? shareId;           // 分享ID
  final String? shareUrl;       // 分享链接
  final String? qrCodeUrl;      // 二维码URL（可选）
  final DateTime? createdAt;    // 创建时间
  final DateTime? expiresAt;    // 过期时间（可选）

  ShareData({
    this.shareId,
    this.shareUrl,
    this.qrCodeUrl,
    this.createdAt,
    this.expiresAt,
  });

  /// 从JSON创建
  factory ShareData.fromJson(Map<String, dynamic> json) {
    return ShareData(
      shareId: json['shareId'],
      shareUrl: json['shareUrl'],
      qrCodeUrl: json['qrCodeUrl'],
      createdAt: json['createdAt'] != null 
          ? DateTime.parse(json['createdAt']) 
          : null,
      expiresAt: json['expiresAt'] != null 
          ? DateTime.parse(json['expiresAt']) 
          : null,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      if (shareId != null) 'shareId': shareId,
      if (shareUrl != null) 'shareUrl': shareUrl,
      if (qrCodeUrl != null) 'qrCodeUrl': qrCodeUrl,
      if (createdAt != null) 'createdAt': createdAt!.toIso8601String(),
      if (expiresAt != null) 'expiresAt': expiresAt!.toIso8601String(),
    };
  }
}

